﻿@model IEnumerable<EmailSender.Models.EmailAddressModel>
@using EmailSender.Models
@using Kendo.Mvc.UI

@{
    ViewBag.Title = "Index";
}

<h2>مدیریت ایمیل ها</h2>

<br />

@(Html.Kendo().Grid<EmailAddressModel>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Command(command =>
        {
            command.Edit();
            command.Destroy();
        }).Width(80);
        columns.AutoGenerate(true);

    })
    .Pageable()
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .Sortable()
    .ClientDetailTemplateId("template")
    .Filterable()
    .DataSource(dataSource => dataSource
        .Ajax()
        //.Model(model => model.Id(e => e.EmailId))
        .Read(read => read.Action("EmailAddress_Read", "EmailAddress"))
        .Update(update => update.Action("Edit", "EmailAddress"))
        .Create("Create", "EmailAddress")
        .Destroy("Delete", "EmailAddress")
        .Model(m => m.Id(c => c.EmailId))
        .PageSize(20)
     )
      .Events(events => events.DataBound("dataBound"))
      )

<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<CategoryModel>()
            .Name("grid_#=EmailId#")
            .Columns(columns =>
            {
                columns.Command(command => command.Destroy().Text("حذف"));
                columns.Bound(c => c.ID).Width(70);
                columns.Bound(c => c.CatCode).Width(110);
                columns.Bound(c => c.CatTitle);
            })
            .Editable(edit => edit.ConfirmDelete("آیا از حذف مورد اطمینان دارید؟"))
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(5)
                .Destroy("Delete", "EmailCategory",new { emailId = "#=EmailId#"})
                .Read(read => read.Action("Grid_Read_ByEmailId", "EmailAddress", new { emailId = "#=EmailId#" }))
                .Model(model=>model.Id("ID"))
            )
            .Pageable()
            .ToClientTemplate()
    )
</script>
<script>
    function dataBound() {
        this.expandRow(this.tbody.find("tr.k-master-row").first());
    }
</script>

